﻿using TestBat.IModels.Domain;
using TestBat.IModels.Services;
using TestBat.IViewModels.Workspaces.Results;
using TestBat.ViewModels.Attributes;
using TestBat.ViewModels.Base;
using TestBat.ServiceLocator;
using Ninject.Core.Parameters;

namespace TestBat.ViewModels.Workspaces.Results
{
    public class ResultTraineeViewModel : ListItemViewModel, IResultTraineeViewModel
    {
        public ResultTraineeViewModel(ITest test, IResultsService resultsService)
        {
            this.test = test;
            this.resultsService = resultsService;
            this.resultTestTaskList = null;
        }

        public ITestResults TestResults
        {
            get
            {
                if (traineeResults == null)
                    traineeResults = resultsService.GetResults(test);

                return traineeResults;
            }
            private set
            {
                traineeResults = value;
                NotifyPropertyChanged(() => TestResults);
            }
        }

        public IResultTestTaskListViewModel ResultTestTaskList
        {
            get
            {
                if (resultTestTaskList == null)
                    resultTestTaskList = DefaultServiceLocator.Get<IResultTestTaskListViewModel>(With.Parameters.ConstructorArgument("test", test));
                return resultTestTaskList;
            }
        }

        //public ICommand RefreshCommand
        //{
        //    get
        //    {
        //        return new RelayCommand(ctx => Refresh());
        //    }
        //}

        public override void OnLostFocus()
        {
        }

        public ITrainee Trainee
        {
            get
            {
                return test.Trainee;
            }
        }

        //[BusinessErrorDialog]
        //private void Refresh()
        //{
        //    TraineeResults = resultsService.GetResults(schedule, Trainee, true);
        //}

        private IResultTestTaskListViewModel resultTestTaskList;
        private readonly IResultsService resultsService;
        private ITestResults traineeResults;
        private readonly ITest test;
    }
}
